<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>函数AOP应用场景</title>
</head>

<body>
    <script>
        //实现一个,函数代码执行,之后,展示开始和结束事件的代码
        var count = function () {
            let sum = ''
            for (let i = 0; i < 1000000; i++) {
                sum += '<li>' + i + '</li>'
            }

        }


        Function.prototype.before = function (beforeFn) {
            let _self = this
            return function () {
                beforeFn.apply(this, arguments)
                _self.apply(this, arguments)
            }
        }
        Function.prototype.after = function (afterFn) {
            let _self = this
            return function () {
                _self.apply(this, arguments)
                afterFn.apply(this, arguments)
            }
        }
        // 所有的函数都可以进行包装
        count = count.before(function () {
            console.log(+new Date());
        }).after(function () {
            console.log(+new Date());
        })

        count()
    </script>
</body>

</html>